#include "Transform.h"
#include <glm/gtx/quaternion.hpp>
#include <glm/gtc/matrix_transform.hpp>

void Transform::UpdateMatrix()
{
	if (isDirty)
	{
		mMatrix = glm::scale(glm::mat4(1.0f), mScale);
		mMatrix = glm::rotate(mMatrix, mRotation.x * 180.0f / glm::pi<float>(), glm::vec3(1.0f, 0, 0));
		mMatrix = glm::rotate(mMatrix, mRotation.y * 180.0f / glm::pi<float>(), glm::vec3(0, 1.0f, 0));
		mMatrix = glm::rotate(mMatrix, mRotation.z * 180.0f / glm::pi<float>(), glm::vec3(0, 0, 1.0f));
		mMatrix = glm::translate(mMatrix, mPosition);
		mInverseMatrix = glm::inverse(mMatrix);
		isDirty = false;
	}
}

glm::mat4x4 Transform::TRS(glm::vec3 translate, glm::quat rotation, glm::vec3 scale)
{
	glm::mat4x4 matrix = glm::scale(glm::mat4(1.0f), scale);
	matrix = glm::mat4_cast(rotation) * matrix;
	matrix = glm::translate(matrix, translate);
	return matrix;
}